#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int spcon(int v, int a, int s){
	return v*v + 2*a*s;
}

int sps(int v, int a, int V){
	return int(ceil((V*V - v*v)*1.0 / (2 * a)));
}
void pertile(){
	int n, m, L, V;
	cin >> n >> m >> L >> V;
	int pcnt;
	while(n--){
		int d,v,a;
		cin >> d >> v >> a;
		if(v <= V && a <= 0) continue;		//drop common car
		else if(v > V && a >= 0){
			pcnt++;
			continue;
		}
		if(v > V && a <= 0){
			pcnt++;
			continue;
		}
		if(v < V && a > 0 && spcon(v,a,L-d) <= V)continue;	//drop ...
		cout<<pcnt<<' ';
		int sens[m];
		for(auto& i:sens){
			cin >> i;
		}
		int cnt = 0;
		for(auto i:sens) if(true) cnt++;
		cout<<cnt<<endl;
		
	}
}

int main(){
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	int t;
	cin >> t;
	while(t--){
		pertile();
	}
	return 0;
}
